base64Table=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /);
str=$1
len=${#str}
result=""

for ((j=1;j<len+1;j++))
do
    a=$(printf "%d" "'${str:j-1:1}")
    for ((i=0;i<8;i++))
    do
        let array[8*j-i-1]=a%2
        let a=a/2
    done
done

for ((i=0;i<${#array[*]}/6;i++))
do
    sum=0
    for((j=0;j<6;j++))
    do
    let sum=sum*2+array[i*6+j]
    done
    result=${result}${base64Table[$sum]}
done

if [ $((len*8-i*6)) = 4 ];then
    sum=0
    
    for((j=0;j<6;j++))
    do
    let sum=sum*2+array[i*6+j]
    done
    
    result=${result}${base64Table[$sum]}
    result=${result}=
    elif [ $((len*8-i*6)) = 2 ];then
        sum=0
        for((j=0;j<6;j++))
        do
        let sum=sum*2+array[i*6+j]
        done
        result=${result}${base64Table[$sum]}
        result=${result}==
fi
echo $result